﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <base href="<%=basePath%>">
    <!-- jsp文件头和头部 -->
    <%@ include file="../admin/top.jsp" %>
</head>
<body>
<div class="container-fluid" id="main-container">

    <div id="page-content" class="clearfix">
        <div class="row-fluid">
            <div class="row-fluid">
                <!-- 检索  -->
                <form action="user/list" method="post" name="userForm" id="userForm">
                    <input type="hidden" name="menuId" value="${page.menuId}">
                    <table style="width: 700px">
                        <tr>
                            <td>
						<span class="input-icon">
							<input style="margin-top: 0px;" autocomplete="off" id="nav-search-input" type="text"
                                   name="searchValue" value="${page.searchValue}" placeholder="登录账号名"/>
						</span>
                            </td>
                            <td style="vertical-align:top;">
                                <select class="chzn-select" name="type" data-values="${type}" data-placeholder="请选择类型"
                                        style="vertical-align:top;width: 120px;">
                                    <option value="">选择类型</option>
                                    <option value="0"
                                            <c:if test="${type == 0}">selected</c:if> >系统账号
                                    </option>
                                    <option value="1"
                                            <c:if test="${type == 1}">selected</c:if> >渠道账号
                                    </option>
                                </select>
                            </td>
                            <td style="vertical-align:top;">
                                <select class="chzn-select" name="status" data-values="${status}"
                                        data-placeholder="请选择状态" style="vertical-align:top;width: 120px;">
                                    <option value="">选择状态</option>
                                    <option value="0"
                                            <c:if test="${status == 0}">selected</c:if> >启用
                                    </option>
                                    <option value="1"
                                            <c:if test="${status == 1}">selected</c:if> >禁用
                                    </option>
                                </select>
                            </td>
                            <td style="vertical-align:top;">
                                <select class="chzn-select" name="roleId" data-values="${roleId}"
                                        data-placeholder="请选择角色" style="vertical-align:top;width: 120px;">
                                    <option value="">选择角色</option>
                                    <c:forEach items="${roles}" var="role">
                                        <option value="${role.id}"
                                                <c:if test="${not empty roleId and roleId == role.id}">selected</c:if> >${role.name}</option>
                                    </c:forEach>
                                </select>
                            </td>
                            <td style="vertical-align:top;">
                                <button class="btn btn-mini btn-light" onclick="search();" title="检索">
                                    <i id="nav-search-icon" class="icon-search"></i>
                                </button>
                            </td>
                            <td style="vertical-align:top;">
                                <c:if test="${fn:contains(butSet, 'add')}">
                                    <a class="btn btn-small btn-success" onclick="add();">新增</a>
                                </c:if>
                            </td>
                        </tr>
                    </table>
                    <!-- 检索  -->
                    <table id="table_report" class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th>账号</th>
                            <th>昵称</th>
                            <th>角色</th>
                            <th>账号类型</th>
                            <th>解绑数量</th>
                            <th>渠道归属</th>
                            <th>状态</th>
                            <th>最近登录时间</th>
                            <th>登录ip</th>
                            <th>创建时间</th>
                            <th class="center">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:choose>
                            <c:when test="${not empty users}">
                                <c:forEach items="${users}" var="model">
                                    <tr>
                                        <td>${model.account }</td>
                                        <td>${model.nickname }</td>
                                        <td>${model.role.name }</td>
                                        <c:choose>
                                            <c:when test="${model.type == 0}">
                                                <td style="color: red">系统账号</td>
                                            </c:when>
                                            <c:otherwise>
                                                <td style="color: blue">渠道账号</td>
                                            </c:otherwise>
                                        </c:choose>
                                        <td>${model.unbindNum }</td>
                                        <td>${model.channelAff.name }</td>
                                        <c:choose>
                                            <c:when test="${model.status == 0}">
                                                <td style="color: blue">启用</td>
                                            </c:when>
                                            <c:otherwise>
                                                <td style="color: red">禁用</td>
                                            </c:otherwise>
                                        </c:choose>
                                        <td><fmt:formatDate value="${model.lastLoginTime }"
                                                            pattern="yyyy-MM-dd HH:mm:ss"/></td>
                                        <td>${model.ip }</td>
                                        <td><fmt:formatDate value="${model.createTime }"
                                                            pattern="yyyy-MM-dd HH:mm:ss"/></td>
                                        <td style="width: 60px;">
                                            <div class='hidden-phone visible-desktop btn-group'>
                                                <c:if test="${fn:contains(butSet, 'edit')}">
                                                    <a class='btn btn-mini btn-info' title="编辑"
                                                       onclick="edit('${model.id }');">
                                                        <i class='icon-edit'></i>
                                                    </a>
                                                </c:if>
                                                <c:if test="${fn:contains(butSet, 'forbidden')}">
                                                    <c:choose>
                                                        <c:when test="${model.status == 0}">
                                                            <a class='btn btn-mini btn-danger'
                                                               onclick="forbidden('${model.id }', '${model.status }', '${model.account }');">
                                                                禁用
                                                            </a>
                                                        </c:when>
                                                        <c:otherwise>
                                                            <a class='btn btn-mini btn-info'
                                                               onclick="forbidden('${model.id }', '${model.status }', '${model.account }');">
                                                                启用
                                                            </a>
                                                        </c:otherwise>
                                                    </c:choose>
                                                </c:if>
                                                <c:if test="${fn:contains(butSet, 'del')}">
                                                    <a class='btn btn-mini btn-danger' title="删除"
                                                       onclick="del('${model.id }','${model.account }');">
                                                        <i class='icon-trash'></i>
                                                    </a>
                                                </c:if>
                                            </div>
                                        </td>
                                    </tr>
                                </c:forEach>
                            </c:when>
                            <c:otherwise>
                                <tr class="main_info">
                                    <td colspan="10" class="center">没有相关数据</td>
                                </tr>
                            </c:otherwise>
                        </c:choose>
                        </tbody>
                    </table>
                    <div class="page-header position-relative">
                        <table style="width:100%;">
                            <tr>
                                <td style="vertical-align:top;">
                                    <div class="pagination"
                                         style="float: right;padding-top: 0px;margin-top: 0px;">${page.pageStr}</div>
                                </td>
                            </tr>
                        </table>
                    </div>
                </form>
            </div>
        </div><!--/row-->
    </div><!--/#page-content-->
</div><!--/.fluid-container#main-container-->
<!-- 返回顶部  -->
<a href="#" id="btn-scroll-up" class="btn btn-small btn-inverse">
    <i class="icon-double-angle-up icon-only"></i>
</a>
<!-- 引入 -->
<script type="text/javascript">window.jQuery || document.write("<script src='static/js/jquery-1.9.1.min.js'>\x3C/script>");</script>
<script src="static/js/bootstrap.min.js"></script>
<script src="static/js/ace-elements.min.js"></script>
<script src="static/js/ace.min.js"></script>

<script type="text/javascript" src="static/js/chosen.jquery.min.js"></script><!-- 下拉框 -->
<script type="text/javascript" src="static/js/bootstrap-datepicker.min.js"></script><!-- 日期框 -->
<script type="text/javascript" src="static/js/bootbox.min.js"></script><!-- 确认窗口 -->
<!-- 引入 -->
<script type="text/javascript" src="static/js/jquery.tips.js"></script><!--提示框-->
<script type="text/javascript">
    $(top.hangge());

    //检索
    function search() {
        top.jzts();
        $("#userForm").submit();
    }

    //新增
    function add() {
        top.jzts();
        var diag = new top.Dialog();
        diag.Drag = true;
        diag.Title = "添加账号";
        diag.URL = '<%=basePath%>user/toAdd';
        diag.Width = 500;
        diag.Height = 650;
        diag.CancelEvent = function () { //关闭事件
            if (diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none') {
                if ('${page.currentPage}' == '0') {
                    top.jzts();
                    //setTimeout("self.location=self.location",100);
                    $("#userForm").submit();
                } else {
                    nextPage(${page.currentPage});
                }
            }
            diag.close();
        };
        diag.show();
    }

    //修改
    function edit(id) {
        top.jzts();
        var diag = new top.Dialog();
        diag.Drag = true;
        diag.Title = "编辑账号";
        diag.URL = '<%=basePath%>user/toEdit?id=' + id;
        diag.Width = 500;
        diag.Height = 650;
        diag.CancelEvent = function () { //关闭事件
            if (diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none') {
                nextPage(${page.currentPage});
            }
            diag.close();
        };
        diag.show();
    }

    //删除
    function del(id, account) {
        bootbox.confirm("是否删除[" + account + "]账号?", function (result) {
            if (result) {
                top.jzts();
                var url = "<%=basePath%>user/del?id=" + id + "&tm=" + new Date().getTime();
                $.get(url, function (data) {
                    if (data.code == 200) {
                        nextPage(${page.currentPage});
                    } else {
                        alert(data.msg)
                    }
                });
            }
        });
    }

    //启用、禁用
    function forbidden(id, status, account) {
        var msg = "";
        if (status == 0) {
            msg = "是否禁用[" + account + "]账号？";
            status = 1;
        } else {
            msg = "是否启用[" + account + "]账号？";
            status = 0;
        }
        bootbox.confirm(msg, function (result) {
            if (result) {
                top.jzts();
                var postParam = {"id": id, "status": status};
                var url = "<%=basePath%>user/updateStatus";
                $.post(url, postParam, function (data) {
                    if (data.code == 200) {
                        nextPage(${page.currentPage});
                    }
                });
            }
        });
    }

</script>

<script type="text/javascript">
    $(function () {
        //日期框
        $('.date-picker').datepicker({autoclose: true});
        //下拉框
        $(".chzn-select").chosen({disable_search: true});
        $(".chzn-select-deselect").chosen({allow_single_deselect: true});
        //复选框
        $('table th input:checkbox').on('click', function () {
            var that = this;
            $(this).closest('table').find('tr > td:first-child input:checkbox')
                .each(function () {
                    this.checked = that.checked;
                    $(this).closest('tr').toggleClass('selected');
                });
        });
    });
</script>
</body>
</html>

